Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of a few types #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

timotejroiko
Copy link

Hey,

I ended up focusing on some improvements for the less important data types and flags. Additionally i added some more tests and updated dependencies because why not.

Anyways feel free to take a look, test and pick what you like. If you don't like some specific change let me know and i'll revert

Cheers!


package.json

Update dependencies

test.js

Added tests for:

  • Empty String
  • BigInt > 64 bit
  • NaN
  • Infinity
  • Undefined
  • Function

test-bench2.js

Added benchmarks for measuring performance of different data types

main.js

Changes:

  • separate and clarify flag-only data types
  • added flags for: true, false, big bigint, nan, infinity, undefined, function
  • changed Buffer.alloc to Buffer.allocUnsafe (faster)
  • added support for big bigint (>64bit, stored as hex buffer)
  • serialize functions and retrieve actual functions instead of string representation (breaking change)
  • store undefined as flag and retrieve actual undefined instead of "undefined" (breaking change)

hash.cc

Added short-circuiting for flag-only types

Performance changes:

  • Numbers -> 50% faster writes
  • Booleans -> 100% faster writes and 200% faster reads
  • Bigint -> 50% faster writes
  • Big Bigint -> no longer throws, performance is a bit slower than strings
  • Null -> 50% faster writes, 200% faster reads
  • NaN -> 100% faster writes, 200% faster reads
  • Infinity -> 100% faster writes, 200% faster reads
  • Undefined -> 50% faster writes, 200% faster reads
  • Function -> now returns an actual function, performance is a bit slower than objects

@jhuckaby
Copy link
Owner

jhuckaby commented Mar 1, 2021

Hey @timotejroiko, thanks so much for this! I'll take a look as soon as I have some time.

@jhuckaby
Copy link
Owner

Hey @timotejroiko,

So I have to apologize. I had a bunch of MegaHash changes in my local repo from many months ago that I didn't finish, and kind of forgot about. I really wanted to get those committed, pushed and tagged before I worked on your fork.

Part of these changes was cleaning up the repo folders a bit, and I moved the test scripts into a new test/ subdirectory, and completely redesigned the benchmarking script.

Would it be possible for you to move your test script into there as well? Also, can we rename it from test-bench2.js to something like test-types.js?

I think most of your other changes are "mergeable", and won't conflict with what I changed.

Thanks, and sorry!

@timotejroiko
Copy link
Author

no worries :) im working on some other stuff but i'll get back on it soon.

### package.json
Update dependencies

### test.js
Added tests for:
* Empty String
* BigInt > 64 bit
* NaN
* Infinity
* Undefined
* Function

### test-bench2.js
Added benchmarks for measuring performance of different data types

### main.js
Changes:
* separate and clarify flag-only data types
* added flags for: true, false, big bigint, nan, infinity, undefined, function
* changed Buffer.alloc to Buffer.allocUnsafe (faster)
* add support for big bigint (>64bit, stored as hex buffer)
* serialize functions and retrieve actual functions instead of string representation (breaking change)
* store undefined as flag and retrieve actual undefined instead of "undefined" (breaking change)

### hash.cc
Added short-circuiting for flag-only types

### Performance changes:
* Numbers -> 50% faster writes
* Booleans -> 100% faster writes and 200% faster reads
* Bigint -> 50% faster writes
* Big Bigint -> no longer throws, performance is a bit slower than strings
* Null -> 50% faster writes, 200% faster reads
* NaN -> 100% faster writes, 200% faster reads
* Infinity -> 100% faster writes, 200% faster reads
* Undefined -> 50% faster writes, 200% faster reads
* Function -> now returns an actual function, performance is a bit slower than objects
@timotejroiko
Copy link
Author

i've rebased and moved the file to the test folder, let me know if theres anything else i can do :)

@mfcodeworks
Copy link

Any update on these @jhuckaby? These PRs look pretty great in what they can provide for the repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants